from selenium import webdriver
from time import  sleep
import unittest
class AfterwinTestCase(unittest.TestCase):
    u'''所有case运行前只运行一次'''
    @classmethod
    def setUpClass(cls) :
        print('start')

    u'''登录博客'''
    def setUp(self):
        self.driver= webdriver.Chrome()
        url = "http://afterwin.cn"
        self.driver.get(url)

    def lonin(self,username,password):
        u'''登录'''
        self.driver.find_element_by_link_text("登录").click()
        self.driver.find_element_by_name("username").send_keys(username)
        self.driver.find_element_by_name("password").send_keys(password)
        self.driver.find_element_by_css_selector("button[type='submit']").click()

    def assertLogin(self):
        u'''判断是否获取到登录名称'''
        try:
            resulttext = self.driver.find_element_by_css_selector(".container ul:nth-last-child(1)  li a").text
            print("hahahha"+resulttext)
            return True
        except:
            return False

    def test_1(self):
        u'''登录方法'''
        self.lonin("fan","123456")
        result = self.assertLogin()
        self.assertTrue(result)

    u'''退出博客'''
    def tearDown(self):
        self.driver.quit()

    u'''所有case运行后执行一次'''
    @classmethod
    def tearDownClass(cls):
        print('结束')

    if __name__ == '__main__':  # 运行主函数
        unittest.main()


